package com.chinadci.smartcommunitysystembackstage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chinadci.smartcommunitysystembackstage.entity.ScsNotice;
import com.chinadci.smartcommunitysystembackstage.mapper.ScsNoticeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ScsNoticeService {
    @Autowired
    private ScsNoticeMapper mapper;

    private Logger log= LoggerFactory.getLogger(this.getClass());

    //显示全部社区公告
    public List<ScsNotice> Find(String title){
        log.info("=====显示全部社区公告");
        List<ScsNotice> list=null;
        if (title!="" & title!=null){
            list=mapper.Find("%"+title+"%");
        }else{
            list=mapper.Find("%%");
        }
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setName(list.get(i).getAdmin().get(0).getAName());
        }
        return list;
    }

    //新增社区公告
    public int Insert(ScsNotice scs){
        log.info("=====新增社区公告");
        return mapper.insert(scs);
    }

    //删除社区公告
    public int Del(int id){
        log.info("=====删除社区公告");
        QueryWrapper<ScsNotice> qw=new QueryWrapper<>();
        qw.eq("n_id",id);
        return mapper.delete(qw);
    }

    //修改社区公告
    public int Update(ScsNotice scs){
        log.info("=====修改社区公告");
        return mapper.updateById(scs);
    }

    //修改的时候社区公告
    public List<ScsNotice> Finds(int id){
        log.info("=====修改的时候社区公告");
        List<ScsNotice> list= mapper.Finds(id);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setName(list.get(i).getAdmin().get(0).getAName());
        }
        return list;
    }
}
